{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution(object):\n",
    "    def longestPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: int\n",
    "        \"\"\"\n",
    "        l = list(s)\n",
    "        l.sort()\n",
    "        length = len(l)\n",
    "        \n",
    "        cnt = 0\n",
    "        has_single = False\n",
    "        left = 0\n",
    "        right = 0\n",
    "        \n",
    "        while right < length:\n",
    "            while right < length and l[left] == l[right]:\n",
    "                right = right + 1\n",
    "\n",
    "            cnt = cnt + (right - left)\n",
    "            if (right-left) % 2 == 1:\n",
    "                cnt = cnt - 1\n",
    "                if has_single is False:\n",
    "                    has_single = True\n",
    "                    cnt = cnt + 1\n",
    "            left = right\n",
    "        \n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Solution()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.longestPalindrome(\"abcdefg\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
